package git.LiuZhanHong.Demo3_14;

public class Test {
    public static void main(String[] args) {
        Dog[] dogArr = new Dog[5];
        Dog dog1 = new Dog("小白", 4, "白色");
        Dog dog2 = new Dog("小黑", 3, "黑色");
        Dog dog3 = new Dog("小黄", 5, "黄色");
        dogArr[0] = dog1;
        dogArr[1] = dog2;
        dogArr[2] = dog3;

        //进行增加操作
        System.out.println("----------增加二哈操作 ----------");
        for (int i = 0; i < dogArr.length; i++) {
            if (dogArr[i] == null) {
                Dog newDog = new Dog("二哈", 8, "黑白");
                dogArr[i] = newDog;
                break;
            }
        }
        //输出
        for (int i = 0; i < dogArr.length; i++) {
            if (dogArr[i] != null) {
                System.out.println(dogArr[i].getName() + " " + dogArr[i].getAge() + " " + dogArr[i].getColor());
            }
        }

        System.out.println("----------删除小白操作 ----------");
        Dog[] dogArr2 = new Dog[dogArr.length - 1];
        int count = 0;
        for (int i = 0; i < dogArr2.length; i++) {
            if (!dogArr[i].getName().equals("小白")) {
                dogArr2[count++] = dogArr[i];
            }
        }
        dogArr = dogArr2;
        //输出
        for (int i = 0; i < dogArr.length; i++) {
            if (dogArr[i] != null) {
                System.out.println(dogArr[i].getName() + " " + dogArr[i].getAge() + " " + dogArr[i].getColor());
            }
        }

        System.out.println("----------改名小黑->黑黑操作 ----------");
        for (int i = 0; i < dogArr.length; i++) {
            if (dogArr[i].getName().equals("小黑")) {
                dogArr[i].setName("黑黑");
                break;
            }
        }
         //输出
        for (int i = 0; i < dogArr.length; i++) {
            if (dogArr[i] != null) {
                System.out.println(dogArr[i].getName() + " " + dogArr[i].getAge() + " " + dogArr[i].getColor());
            }
        }
        System.out.println("----------查询全部操作 ----------");
        for (int i = 0; i < dogArr.length; i++) {
            if (dogArr[i] != null) {
                System.out.println(dogArr[i].getName() + " " + dogArr[i].getAge() + " " + dogArr[i].getColor());
            }
        }

    }

}
